package com.lebo.portal.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lebo.portal.constant.Constants;
import com.lebo.portal.controller.base.BaseController;
import com.lebo.portal.model.ActivityQuery;
import com.lebo.portal.model.LoginUser;
import com.lebo.portal.service.ActivityService;
import com.lebo.portal.view.PageInfo;
import com.lebo.portal.view.PageQuery;
import com.lebo.portal.view.PageResult;
import com.lebo.web.domain.Activity;
import com.lebo.web.domain.Room;

@Controller
@RequestMapping("/portal")
public class PortalController extends BaseController {

    @Autowired
    private ActivityService activityService;

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public @ResponseBody String index(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            HttpSession session) {
        session.setAttribute(Constants.SESSION_ACCOUNT_LABLE, new LoginUser());
        return "{\"isOk\":true}";
    }

    @RequestMapping(value = "/room", method = RequestMethod.GET)
    public ModelAndView room(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            ActivityQuery query, PageInfo pageInfo) {
        PageQuery<Activity> pageQuery = new PageQuery<Activity>();
        pageQuery.setPageInfo(pageInfo);
        PageResult<List<Activity>> pageResult = activityService.pagingActivities(pageQuery);

        mv.addObject("pageResult", pageResult);

        Room room = new Room();
        mv.setViewName("portal/room");
        mv.addObject(Constants.SESSION_ACCOUNT_LABLE, user);
        mv.addObject("room", room);
        mv.addObject("pageResult",pageResult);
        return mv;
    }

    @RequestMapping(value = "/videoClip/portal", method = RequestMethod.GET)
    public ModelAndView videoClip(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            ActivityQuery query, PageInfo pageInfo) {

        Room room = new Room();
        mv.setViewName("portal/video");
        mv.addObject(Constants.SESSION_ACCOUNT_LABLE, user);
        mv.addObject("room", room);
        mv.addObject("pageResult",null);
        return mv;
    }

    @RequestMapping(value = "/videoClip/add", method = {RequestMethod.POST,RequestMethod.GET})
    public ModelAndView addVideoClip(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            ActivityQuery query, PageInfo pageInfo) {

        Room room = new Room();
        mv.setViewName("portal/video_add");
        mv.addObject(Constants.SESSION_ACCOUNT_LABLE, user);
        mv.addObject("room", room);
        mv.addObject("pageResult",null);
        return mv;
    }

    @RequestMapping(value = "/videoClip/list", method = {RequestMethod.POST,RequestMethod.GET})
    public ModelAndView listVideoClip(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            ActivityQuery query, PageInfo pageInfo) {

        Room room = new Room();
        mv.setViewName("portal/video_videolist");
        mv.addObject(Constants.SESSION_ACCOUNT_LABLE, user);
        mv.addObject("room", room);
        mv.addObject("pageResult",null);
        return mv;
    }

    @RequestMapping(value = "/activity/add", method = {RequestMethod.POST,RequestMethod.GET})
    public ModelAndView addActivity(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            ActivityQuery query, PageInfo pageInfo) {

        Room room = new Room();
        mv.setViewName("portal/activity_add");
        mv.addObject(Constants.SESSION_ACCOUNT_LABLE, user);
        mv.addObject("room", room);
        mv.addObject("pageResult",null);
        return mv;
    }

    @RequestMapping(value = "/mediacloud", method = {RequestMethod.POST,RequestMethod.GET})
    public ModelAndView mediaCloud(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            ActivityQuery query, PageInfo pageInfo) {

        mv.setViewName("portal/mediacloud");
        mv.addObject(Constants.SESSION_ACCOUNT_LABLE, user);
        mv.addObject("pageResult",null);
        return mv;
    }

    @RequestMapping(value = "/mediacloud/live", method = {RequestMethod.POST,RequestMethod.GET})
    public ModelAndView mediaCloudLive(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            ActivityQuery query, PageInfo pageInfo) {

        mv.setViewName("portal/mediacloud_live");
        mv.addObject(Constants.SESSION_ACCOUNT_LABLE, user);
        mv.addObject("pageResult",null);
        return mv;
    }

    @RequestMapping(value = "/mediacloud/video", method = {RequestMethod.POST,RequestMethod.GET})
    public ModelAndView mediaCloudVideo(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            ActivityQuery query, PageInfo pageInfo) {

        mv.setViewName("portal/mediacloud_video");
        mv.addObject(Constants.SESSION_ACCOUNT_LABLE, user);
        mv.addObject("pageResult",null);
        return mv;
    }

    @RequestMapping(value = "/mediacloud/upload", method = {RequestMethod.POST,RequestMethod.GET})
    public ModelAndView mediaCloudUpload(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            ActivityQuery query, PageInfo pageInfo) {

        mv.setViewName("portal/mediacloud_upload");
        mv.addObject(Constants.SESSION_ACCOUNT_LABLE, user);
        mv.addObject("pageResult",null);
        return mv;
    }


    @RequestMapping(value = "/mediacloud/save", method = {RequestMethod.POST,RequestMethod.GET})
    public @ResponseBody String mediaCloudSave(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            ActivityQuery query, PageInfo pageInfo) {
        return "{\"isOk\":true}";
    }

    @RequestMapping(value = "/mediacloud/delete", method = {RequestMethod.POST,RequestMethod.GET})
    public @ResponseBody String mediaCloudDelete(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            ActivityQuery query, PageInfo pageInfo) {
        return "{\"isOk\":true}";
    }

    @RequestMapping(value = "/shop", method = {RequestMethod.POST,RequestMethod.GET})
    public ModelAndView shop(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            ActivityQuery query, PageInfo pageInfo) {

        mv.setViewName("portal/shop");
        mv.addObject(Constants.SESSION_ACCOUNT_LABLE, user);
        mv.addObject("pageResult",null);
        return mv;
    }

    @RequestMapping(value = "/device", method = {RequestMethod.POST,RequestMethod.GET})
    public ModelAndView device(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            ActivityQuery query, PageInfo pageInfo) {

        mv.setViewName("portal/device");
        mv.addObject(Constants.SESSION_ACCOUNT_LABLE, user);
        mv.addObject("pageResult",null);
        return mv;
    }

    @RequestMapping(value = "/device/dosave", method = {RequestMethod.POST,RequestMethod.GET})
    public @ResponseBody String deviceSave(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            ActivityQuery query, PageInfo pageInfo) {
        return "{\"isOk\":true}";
    }

    @RequestMapping(value = "/activity/unBindDevice", method = {RequestMethod.POST,RequestMethod.GET})
    public @ResponseBody String unBindDevice(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user,
            String id, String device) {
        return "{\"isOk\":true}";
    }

    @RequestMapping(value = "/liveroom/info", method = {RequestMethod.POST,RequestMethod.GET})
    public ModelAndView liveRoom(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user) {

        mv.setViewName("portal/liveroom");
        mv.addObject(Constants.SESSION_ACCOUNT_LABLE, user);
        mv.addObject("pageResult",null);
        return mv;
    }

    @RequestMapping(value = "/publish", method = {RequestMethod.POST,RequestMethod.GET})
    public ModelAndView publish(ModelAndView mv, @ModelAttribute(Constants.SESSION_ACCOUNT_LABLE) LoginUser user) {

        mv.setViewName("portal/publish");
        mv.addObject(Constants.SESSION_ACCOUNT_LABLE, user);
        mv.addObject("pageResult",null);
        return mv;
    }
}